L1-071 前世档案
题目 L1-071 前世档案
思路分析
对于节点i 左孩子为2i 右孩子为2i+1
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
using PII = pair<int,int>;
using Pll = pair<ll,ll>;
int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};
const int inf = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m;cin>>n>>m;
int sum=pow(2,n);
while(m--){
int u=1;
string s;cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='y') u=2*u;
else if(s[i]=='n') u=2*u+1;
}
cout<<u-sum+1<<endl;
}
return 0;
}
同类题型
视频讲解
⬅️ L1-070 吃火锅 🏠 00-天梯赛 ➡️ L1-072 刮刮彩票
💬 评论